package com.viaas.certification.image;

import com.viaas.certification.image.AIVirtualPlayer;
import com.viaas.certification.image.action.AIModeManager;
import com.viaas.certification.image.command.ChatCommand;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Random;

public class Main extends JavaPlugin implements Listener {
    private final AIVirtualPlayer aiPlayer = new AIVirtualPlayer("虚拟玩家001");

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
        AIModeManager aiModeManager = new AIModeManager(this);
        Bukkit.getScheduler().runTaskTimer(this, aiPlayer::simulateAIChat, 200L, 600L);
        Bukkit.getScheduler().runTaskTimer(this, aiPlayer::toggleAIOnline, 1200L, 3600L);
        // 注册命令
        getCommand("ai").setExecutor(new ChatCommand(aiModeManager));
        Bukkit.getLogger().info("Minecraft AI Plugin 已加载！");
    }

    @Override
    public void onDisable() {
        Bukkit.getLogger().info("Minecraft AI Plugin 已卸载！");
    }

    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {
        Player player = event.getPlayer();
        String message = event.getMessage();
        aiPlayer.respondToChat(player, message);
    }
}
